#!/bin/bash

# 全局变量
VERSION=$1
INSTALL_PATH="/home/xxx"
CPU_NUM=$(grep -c "^processor" /proc/cpuinfo) # CPU核数
IP_ADDR=$(ip addr show | grep 'inet ' | awk '{print $2}' | cut -d/ -f1 | head 1) # IP地址
OS_TYPE=$(source /etc/os-release; echo $ID)
BASE_ARCH=$(uname -m)

# 获取第N个提交ID，N可以根据需要调整
NTH_COMMIT_ID=$(git log --pretty=format:"%H" | sed -n "${N}p")

# 错误处理函数
error_exit() {
    echo "$1" 1>&2
    exit 1
}

# 检查是否在git仓库中
git status >/dev/null 2>&1 || error_exit "Not a git repository"

# 重置到指定提交并强制推送
git reset --hard "$NTH_COMMIT_ID" || error_exit "Failed to reset to commit $NTH_COMMIT_ID"
git push -f origin HEAD || error_exit "Failed to force push"

# 删除并复制文件，添加到git并提交
rm -rf ../hpcrunner/.git || error_exit "Failed to remove .git directory"
cp -rf ../hpcrunner/* . || error_exit "Failed to copy files"
git add . || error_exit "Failed to add files to git"
git commit -m "Your commit message here" || error_exit "Failed to commit changes"
git push || error_exit "Failed to push changes"